var markers = [];
var map = null;

//餐饮服务列表
var FoodServiceList = [{
    Comments: "",
    Enabled: 1,
    Latitude: 22.842081,
    ListenCount: 0,
    Longitude: 108.271483,
    RecordIndex: 9,
    SpotContent: "中餐饮食风味小吃、定型饮料、快餐、粉、面。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "海洋湾餐厅",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.840058,
    ListenCount: 0,
    Longitude: 108.271671,
    RecordIndex: 9,
    SpotContent: "自制做各类奶茶、果汁和干捞粉。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "4D影院奶茶店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.842752,
    ListenCount: 0,
    Longitude: 108.273931,
    RecordIndex: 9,
    SpotContent: "自制做各类冰淇淋、冷饮和创意食品等。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "冰淇淋店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.841648,
    ListenCount: 0,
    Longitude: 108.278669,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "蛇园便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.843601,
    ListenCount: 0,
    Longitude: 108.271352,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "自控飞机便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.840237,
    ListenCount: 0,
    Longitude: 108.277829,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "鸟馆便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.839995,
    ListenCount: 0,
    Longitude: 108.275682,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "新海狮馆便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.841856,
    ListenCount: 0,
    Longitude: 108.27478,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "猴山便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.842598,
    ListenCount: 0,
    Longitude: 108.274321,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "黑猩猩馆便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.842785,
    ListenCount: 0,
    Longitude: 108.276639,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "园外1号便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.842914,
    ListenCount: 0,
    Longitude: 108.272956,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "主题游乐场小卖部",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.839142,
    ListenCount: 0,
    Longitude: 108.275408,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "大象馆便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.843055,
    ListenCount: 0,
    Longitude: 108.275561,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "蘑菇亭便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.841423,
    ListenCount: 0,
    Longitude: 108.275965,
    RecordIndex: 9,
    SpotContent: "包装食品、定型饮料、日用品。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "两爬馆便利店",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.841707,
    ListenCount: 0,
    Longitude: 108.27319,
    RecordIndex: 9,
    SpotContent: "快餐、粉类、蛋点类、自做奶茶、果汁、定型饮料、包装食品以及其他食品加工等。",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_07.png",
    SpotIntroduction: "",
    SpotLogo: "",
    SpotName: "水世界餐厅以及配送点",
    SpotType: 2,
    VisitCount: 1,
    VoicePath: null
}];
//卫生间列表
var BathroomList = [{
    Comments: "",
    Enabled: 1,
    Latitude: 22.838739,
    ListenCount: 0,
    Longitude: 108.274552,
    RecordIndex: 9,
    SpotContent: "",
    SpotGuid: "E5C3F25A-9824-48A2-BFBF-493D55557A61",
    SpotID: 87,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "大象馆公共厕所",
    SpotType: 1,
    VisitCount: 1,
    VoicePath: null
},{
    Comments: "",
    Enabled: 1,
    Latitude: 22.841108,
    ListenCount: 0,
    Longitude: 108.274992,
    RecordIndex: 22,
    SpotContent: "",
    SpotGuid: "C26BB3FD-B636-4034-8459-9FE9CAE695F8",
    SpotID: 93,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "猴馆公共厕所",
    SpotType: 1,
    VisitCount: 6,
    VoicePath: null
}, {
    Comments: "",
    Enabled: 1,
    Latitude: 22.842503,
    ListenCount: 0,
    Longitude: 108.274063,
    RecordIndex: 28,
    SpotContent: "",
    SpotGuid: "411AA37B-43AC-46B0-9588-9E69EA341FBE",
    SpotID: 89,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "加勒比水上世界公共厕所",
    SpotType: 1,
    VisitCount: 1,
    VoicePath: null
}, {
    Comments: "",
    Enabled: 1,
    Latitude: 22.838269,
    ListenCount: 0,
    Longitude: 108.275823,
    RecordIndex: 32,
    SpotContent: "",
    SpotGuid: "260520F4-BE18-47EE-B8FE-DF1A9CFCF3C1",
    SpotID: 91,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "梦幻剧场公共厕所",
    SpotType: 1,
    VisitCount: 1,
    VoicePath: null
}, {
    Comments: "",
    Enabled: 1,
    Latitude: 22.840168,
    ListenCount: 0,
    Longitude: 108.277885,
    RecordIndex: 34,
    SpotContent: "",
    SpotGuid: "88C3C61F-2ADD-4424-A222-BE7A5C217C47",
    SpotID: 88,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "鸟馆公共厕所",
    SpotType: 1,
    VisitCount: 2,
    VoicePath: null
}, {
    Comments: "",
    Enabled: 1,
    Latitude: 22.839722,
    ListenCount: 0,
    Longitude: 108.27351,
    RecordIndex: 49,
    SpotContent: "",
    SpotGuid: "A095FF3A-053B-4AD5-9E25-8E4F39FD5156",
    SpotID: 92,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "熊园公共厕所",
    SpotType: 1,
    VisitCount: 5,
    VoicePath: null
}, {
    Comments: "",
    Enabled: 1,
    Latitude: 22.842374,
    ListenCount: 0,
    Longitude: 108.277467,
    RecordIndex: 51,
    SpotContent: "",
    SpotGuid: "08346C94-2EA3-454E-8BDB-134EA40C3DED",
    SpotID: 90,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "鹦鹉园公共厕所",
    SpotType: 1,
    VisitCount: 1,
    VoicePath: null
}, {
    Comments: "",
    Enabled: 1,
    Latitude: 22.842607,
    ListenCount: 0,
    Longitude: 108.277989,
    RecordIndex: 53,
    SpotContent: "",
    SpotGuid: "628B13C6-B7CC-474D-846A-3D6105304A31",
    SpotID: 85,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "园外公共厕所",
    SpotType: 1,
    VisitCount: 1,
    VoicePath: null
}, {
    Comments: "",
    Enabled: 1,
    Latitude: 22.842189,
    ListenCount: 0,
    Longitude: 108.271578,
    RecordIndex: 56,
    SpotContent: "",
    SpotGuid: "37DCEE9B-1560-463D-AA7C-252D0D1F6A0E",
    SpotID: 96,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "暂养池公共厕所",
    SpotType: 1,
    VisitCount: 0,
    VoicePath: null
}, {
    Comments: "",
    Enabled: 1,
    Latitude: 22.843406,
    ListenCount: 0,
    Longitude: 108.272019,
    RecordIndex: 59,
    SpotContent: "",
    SpotGuid: "ED388AFA-E36F-4328-949A-D62F53AAA913",
    SpotID: 84,
    SpotIcon: "/Images/tour/map_icon_04.png",
    SpotIntroduction: "",
    SpotLogo: "/DefaultMain.html?p=2030",
    SpotName: "主题乐园区公共厕所",
    SpotType: 1,
    VisitCount: 2,
    VoicePath: null
}];


$(function () {
    window.onload = function () {
        Global.initial();
    }
    var tabIndex = Util.urlParam("index");
    Util.SwapTab("#J_AnimalsServiceTab", "li", "#J_AnimalsServiceContent", ".tab-pane", "active", "click", function (index) {
        switch (index) {
            case 2:
                mapInit();
                break;
        }
    });

    if (tabIndex) {
        $("#J_AnimalsServiceTab li").eq(tabIndex).trigger('click');
    } else {
        $("#J_AnimalsServiceTab li").eq(0).trigger('click');
    }

    var MoudlePrice = 1010; //园区票价

    GetArticleMoudleInfo(1000, $("#AnimalsAdvice")); //游园指南
    GetArticleMoudleInfo(1010, $("#AnimalsTicketPrice")); //票价信息
    //    GetArticleMoudleInfo(1020, $("#AnimalsTime")); //上班时间
    //    GetArticleMoudleInfo(1030, $("#AnimalsProblem")); //常见问题
    //    GetArticleMoudleInfo(1040, $("#AnimalsTraffic")); //交通指引


    GetTypeDetail(46);

    function GetTypeDetail(typeid) {
        Service.post({
            url: "/ArticleTypeService.svc/GetArticleTypeByID",
            params: {
                ArticleType: typeid
            },
            success: function (response) {
                if (response.Remarks) {
                    $(".sub-title").html(response.Remarks);
                }
            }
        })

    }

    function GetArticleMoudleInfo(ArticleMoudleID, $contain) {
        //生成文章栏目下拉菜单
        Service.post({
            url: "/ArticleInfoService.svc/GetArticleMoudleInfo",
            params: {
                ArticleMoudleID: ArticleMoudleID
            },
            success: function (response) {
                if (response.ArticleMoudleID == MoudlePrice) {
                    var item = $.parseJSON(response.MoudleData);
                    $("#ZoomManPriceEm").html(item.ZoomManPrice)
                    $("#ZoomChildrenPriceEm").html(item.ZoomChildrenPrice)
                    $("#ZoomStudentPriceEm").html(item.ZoomStudentPrice)
                    $("#ZoomOldManPriceEm").html(item.ZoomOldManPrice)

                    $("#ZoomYearManPriceEm").html(item.ZoomYearManPrice)
                    $("#ZoomYearChildrenPriceEm").html(item.ZoomYearChildrenPrice)
                    $("#ZoomHalfYearManPriceEm").html(item.ZoomHalfYearManPrice)
                    $("#ZoomHalfYearChildrenPriceEm").html(item.ZoomHalfYearChildrenPrice)

                    $("#WaterManPriceEm").html(item.WaterManPrice)
                    $("#WaterChildrenPriceEm").html(item.WaterChildrenPrice)
                    $("#WaterStudentPriceEm").html(item.WaterStudentPrice)
                    $("#WaterOldManPriceEm").html(item.WaterOldManPrice)
                    $("#ZoomWaterManPriceEm").html(item.ZoomWaterManPrice)
                    $("#ZoomWaterChildrenPriceEm").html(item.ZoomWaterChildrenPrice)
                    $("#ZoomWaterStudentPriceEm").html(item.ZoomWaterStudentPrice)
                    $("#ZoomWaterOldManPriceEm").html(item.ZoomWaterOldManPrice)
                } else {
                    $contain.html(response.MoudleData);
                }
            }
        });
    }

})

function bindClick() {
    //餐饮和卫生间位置查看切换按钮事件
    $(".parent-menu").unbind("click").click(function () {
        //if ($(this).hasClass('active') == false) {
        $('.parent-menu').removeClass('active');
        $(this).addClass('active');
        var _type = $(this).data("type");
        if (_type == 0) {
            markers = FoodServiceList;
        } else {
            markers = BathroomList;
        }
        showMarkers();
        //}
    })
    $(".parent-menu").eq(0).click();
}

function mapInit() {
    map = new BMap.Map("J_ZooMap");
    map.centerAndZoom(new BMap.Point(108.275073, 22.841026), 18);
    map.enableScrollWheelZoom(true);
    bindClick();
}

//显示景点标注
function showMarkers() {
    //showTypes = mapMenuType;
    map.clearOverlays();
    $.each(markers, function (index, mapMarker) {
        makeMarker(mapMarker);
    });
    // if (screenID) {
    //     showScreenMarker(screenID);
    // }
}

function makeMarker(json) {
    //$('#SpotLogo').prop("src", json.SpotLogo);
    //$('#SpotName').html(json.SpotName);
    //$('#SpotContent').html(json.SpotContent);
    //var oHtml = $('#J_DetailPopup').html();
    if (!json.Longitude || !json.Latitude) {
        return;
    }
    console.log(json);
    var marker = new BMap.Marker(new BMap.Point(json.Longitude, json.Latitude), {
        icon: get_myicon(json.SpotIcon)
    });

    var label = new BMap.Label('<span title="' + json.SpotContent + '">' + json.SpotName + '</span>', {
        offset: new BMap.Size(20, -10)
    });
    marker.setLabel(label);
    map.addOverlay(marker);
    // marker.addEventListener("click", function() {
    //     layer.open({
    //         type: 1,
    //         title: false,
    //         closeBtn: 0,
    //         shadeClose: false,
    //         shade: 0.5,
    //         area: ['960px', 'auto'],
    //         skin: 'layui-layer-nobg',
    //         content: oHtml,
    //         success: function(layero, index) {
    //             bindSoptInfo(json);
    //             VisitCountIncrease(json.SpotID);
    //         }
    //     });
    // });
}

//设置图标
function get_myicon(iconPath) {
    if (iconPath == null || iconPath == '') {
        iconPath = "/images/tour/map_icon_02.png";
    }
    return new BMap.Icon(iconPath, new BMap.Size(32, 35), {
        offset: new BMap.Size(-32, -47),
        imageOffset: new BMap.Size(0, 0)
    });
}